package com.hsq.commons.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyDirectory {

	public static void main(String args[]) throws IOException {
		String url1 = "e:/1";
		String url2 = "e:/2";
		CopyDirectory.copy(url2, url1);
	}

	public static void copy(String inFile, String outFile) {
		try {
			(new File(outFile)).mkdirs();
			File[] file = (new File(inFile)).listFiles();
			for (int i = 0; i < file.length; i++) {
				if (file[i].isFile()) {
					FileInputStream input = new FileInputStream(file[i]);
					FileOutputStream output = new FileOutputStream(outFile
							+ "/" + file[i].getName());
					byte[] b = new byte[1024 * 5];
					int len;
					while ((len = input.read(b)) != -1) {
						output.write(b, 0, len);
					}
					output.flush();
					output.close();
					input.close();
				}
				if (file[i].isDirectory()) {
					copy(inFile + "/" + file[i].getName(), outFile + "/"
							+ file[i].getName());
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
